package com.gitee.wsl.serialization.reflect

import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.properties.Properties
import kotlinx.serialization.serializer

class KotlinXPropertiesReflectMethod(
     val properties: Properties
) : ReflectMethod {

    @OptIn(ExperimentalSerializationApi::class)
    override fun findValue(obj: Any, name: String): Any? {
        println("Looking for `$name` in `$obj`")
        val serializer = properties.serializersModule.serializer(obj::class, emptyList(), false)
        val map = properties.encodeToMap(serializer, obj)
        return map[name]
    }
}